﻿using Newtonsoft.Json;

namespace BaseExtendsions;

public class IJsonConverter<TConcrete> : JsonConverter
{
    public override bool CanConvert(Type objectType)
    {
        //我们能转换任何东西
        return true;
    }

    public override object ReadJson(JsonReader reader, Type objectType, object existingValue, JsonSerializer serializer)
    {
        //显性指定要转换的实现类
        return serializer.Deserialize<TConcrete>(reader);
    }

    public override void WriteJson(JsonWriter writer, object value, JsonSerializer serializer)
    {
        //默认序列化流程
        serializer.Serialize(writer, value);
    }

}
